//
//  JGOrderDetailsController.m
//  JGRider
//
//  Created by 单启志 on 2018/2/27.
//  Copyright © 2018年 ffq. All rights reserved.
//

#import "JGOrderDetailsController.h"
#import "JGOrderDetailsCell.h"
#import "JGLogisticsDetailsCell.h"
#import "JGOrderCommentCell.h"
#import "JGLogisticsDetailsModel.h"
#import "JGLogisticsDetailsFooterView.h"
@interface JGOrderDetailsController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)UITableView *tableView;
@property(nonatomic,strong)NSArray *datas;
@property(nonatomic,strong)NSArray *logisticsDetailsDatas;//物流数据
@end

@implementation JGOrderDetailsController
static NSString *orderDetailsCellId=@"orderDetailsCell";
static NSString *logisticsDetailsCellId=@"logisticsDetailsCell";
static NSString *orderCommentCellId=@"orderCommentCell";
- (void)viewDidLoad {
    [super viewDidLoad];
    [self configSubViews];
}

-(void)configSubViews{
    self.title=@"订单详情";
    self.logisticsDetailsDatas=[JGLogisticsDetailsModel models];
    [self.view addSubview:self.tableView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];

}

#pragma mark - tableview delegate

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 3;
}
//section头
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    if (section==1) {
       UIView *headerView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, JGScreenW, AdaptedHeight(28))];
        headerView.backgroundColor=[UIColor whiteColor];

        UILabel *lab=[[UILabel alloc]initWithFrame:CGRectMake(AdaptedWidth(16), AdaptedHeight(14), 100, 17)];
        lab.text=@"物流详情";
        lab.font=[UIFont fontWithName:@ "Helvetica-Bold"  size:(14.0)];
        lab.textColor=HEXCOLOR(0xfea129);
        [headerView addSubview:lab];
        return headerView;
    }
    return nil;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section==1) {
        return AdaptedHeight(14)+16;
    }
    return 0;
}
//section脚
-(UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    if (section==1) {
    JGLogisticsDetailsFooterView*footerView=[[JGLogisticsDetailsFooterView alloc]initWithFrame:CGRectMake(0, 0, JGScreenW, AdaptedHeight(53))];

        footerView.backgroundColor=[UIColor clearColor];
        return footerView;
    }
    return nil;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    if (section==1) {
        return AdaptedHeight(53);
    }
    return 0;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section==0) {
        return 1;
    }else if (section==1){
        return self.logisticsDetailsDatas.count;
    }else{
        return 1;
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    if (indexPath.section==0) {
        return [tableView fd_heightForCellWithIdentifier:orderDetailsCellId configuration:^(JGOrderDetailsCell *cell) {
            //cell.model=self.datas[indexPath.row];
        }];
    }else if (indexPath.section==1) {
        return [tableView fd_heightForCellWithIdentifier:logisticsDetailsCellId configuration:^(JGLogisticsDetailsCell *cell) {
            cell.model=self.logisticsDetailsDatas[indexPath.row];
        }];

    }else{

        return [tableView fd_heightForCellWithIdentifier:orderCommentCellId configuration:^(JGOrderCommentCell *cell) {

        }];
    }

}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    if (indexPath.section==0) {//订单详情

        JGOrderDetailsCell *cell=[tableView dequeueReusableCellWithIdentifier:orderDetailsCellId];
        return cell;
    }else if (indexPath.section==1){//物流详情
        JGLogisticsDetailsCell *cell=[tableView dequeueReusableCellWithIdentifier:logisticsDetailsCellId];
        cell.model=self.logisticsDetailsDatas[indexPath.row];
        return cell;
    }else{//评论
        JGOrderCommentCell *cell=[tableView dequeueReusableCellWithIdentifier:orderCommentCellId];
        return cell;
    }
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{


}

#pragma mark - getter setter
-(UITableView *)tableView{

    if (!_tableView) {

        _tableView =[[UITableView alloc]initWithFrame:CGRectMake(0,self.lmj_navgationBar.height, JGScreenW, JGScreenH-self.lmj_navgationBar.height) style:UITableViewStyleGrouped];

        _tableView.backgroundColor=[UIColor whiteColor];

        [_tableView registerNib:[UINib nibWithNibName:NSStringFromClass([JGOrderDetailsCell class]) bundle:nil] forCellReuseIdentifier:orderDetailsCellId];
        [_tableView registerNib:[UINib nibWithNibName:NSStringFromClass([JGLogisticsDetailsCell class]) bundle:nil] forCellReuseIdentifier:logisticsDetailsCellId];
        [_tableView registerNib:[UINib nibWithNibName:NSStringFromClass([JGOrderCommentCell class]) bundle:nil] forCellReuseIdentifier:orderCommentCellId];
        _tableView.showsVerticalScrollIndicator=NO; _tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
        _tableView.delegate=self;
        _tableView.dataSource=self;
    }
    return _tableView;

}

@end
